home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / simula1a / clsactiv.cls < prev    next >
Encoding:
Visual Basic class definition  |  1999-09-13  |  3.5 KB  |  146 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsActiveProcess"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16.     
  17. Private Const TH32CS_SNAPPROCESS As Long = 2&
  18. Private Const MAX_PATH As Integer = 260
  19.  
  20. Private Type PROCESSENTRY32
  21.     dwSize As Long
  22.     cntUsage As Long
  23.     th32ProcessID As Long
  24.     th32DefaultHeapID As Long
  25.     th32ModuleID As Long
  26.     cntThreads As Long
  27.     th32ParentProcessID As Long
  28.     pcPriClassBase As Long
  29.     dwFlags As Long
  30.     szExeFile As String * MAX_PATH
  31.     End Type
  32.  
  33. Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessId As Long) As Long
  34.  
  35.  
  36. Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
  37.  
  38.  
  39. Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
  40.  
  41.  
  42. Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
  43.     Dim ListOfActiveProcess() As PROCESSENTRY32
  44.     
  45. Public Function szExeFile(ByVal Index As Long) As String
  46.  
  47.     szExeFile = ListOfActiveProcess(Index).szExeFile
  48.     
  49. End Function
  50.  
  51.  
  52. Public Function dwFlags(ByVal Index As Long) As Long
  53.  
  54.     dwFlags = ListOfActiveProcess(Index).dwFlags
  55.  
  56.     
  57. End Function
  58.  
  59.  
  60. Public Function pcPriClassBase(ByVal Index As Long) As Long
  61.  
  62.     pcPriClassBase = ListOfActiveProcess(Index).pcPriClassBase
  63. End Function
  64.  
  65.  
  66.  
  67. Public Function th32ParentProcessID(ByVal Index As Long) As Long
  68.  
  69.     th32ParentProcessID = ListOfActiveProcess(Index).th32ParentProcessID
  70. End Function
  71.  
  72.  
  73.  
  74. Public Function cntThreads(ByVal Index As Long) As Long
  75.  
  76.     cntThreads = ListOfActiveProcess(Index).cntThreads
  77. End Function
  78.  
  79.  
  80.  
  81. Public Function thModuleID(ByVal Index As Long) As Long
  82.  
  83.     thModuleID = ListOfActiveProcess(Index).th32ModuleID
  84. End Function
  85.  
  86.  
  87.  
  88. Public Function th32DefaultHeapID(ByVal Index As Long) As Long
  89.  
  90.     th32DefaultHeapID = ListOfActiveProcess(Index).th32DefaultHeapID
  91. End Function
  92.  
  93.  
  94.  
  95. Public Function th32ProcessID(ByVal Index As Long) As Long
  96.  
  97.     th32ProcessID = ListOfActiveProcess(Index).th32ProcessID
  98. End Function
  99.  
  100. Public Function cntUsage(ByVal Index As Long) As Long
  101.  
  102.     cntUsage = ListOfActiveProcess(Index).cntUsage
  103. End Function
  104.  
  105. Public Function dwSize(ByVal Index As Long) As Long
  106.  
  107.     dwSize = ListOfActiveProcess(Index).dwSize
  108. End Function
  109.  
  110. Public Function GetActiveProcess() As Long
  111.  
  112.     Dim hToolhelpSnapshot As Long
  113.     Dim tProcess As PROCESSENTRY32
  114.     Dim r As Long, i As Integer
  115.     hToolhelpSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
  116.  
  117.  
  118.     If hToolhelpSnapshot = 0 Then
  119.         GetActiveProcess = 0
  120.         Exit Function
  121.     End If
  122.  
  123.  
  124.     With tProcess
  125.         .dwSize = Len(tProcess)
  126.         r = ProcessFirst(hToolhelpSnapshot, tProcess)
  127.         ReDim Preserve ListOfActiveProcess(20)
  128.  
  129.  
  130.         Do While r
  131.             i = i + 1
  132.             If i Mod 20 = 0 Then ReDim Preserve ListOfActiveProcess(i + 20)
  133.             ListOfActiveProcess(i) = tProcess
  134.             r = ProcessNext(hToolhelpSnapshot, tProcess)
  135.         Loop
  136.  
  137.     End With
  138.  
  139.     GetActiveProcess = i
  140.     Call CloseHandle(hToolhelpSnapshot)
  141. End Function
  142.  
  143.  
  144.  
  145.  
  146.